package com.batch.controller;

import jakarta.annotation.Resource;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.JobParametersInvalidException;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
import org.springframework.batch.core.repository.JobRestartException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BatchController {
	@Resource
	JobLauncher jobLauncher;
	@Resource
	Job job;
	@GetMapping("/batch")
	void batch(){
		try {
			JobParameters jobParameters=new JobParametersBuilder().toJobParameters();
			jobLauncher.run(job,jobParameters);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
